﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace SilverBoxClient
{
    class QRCodeDownloader
    {
        private const String URL_START = "http://cli.im/qr?text=";
        private const String URL_END = "&level=L&size=260";
        private const String FILE_LOCATION = "./QRCode.png";

        public WebClient client = new WebClient();

        public bool downloadByContent(String content)
        {
            String url = this.getUrlByContent(content);
            return downloadByUrl(url);
        }

        public bool downloadByUrl(String url)
        {
            try
            {
                client.DownloadFile(url, FILE_LOCATION);
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }

        public String getUrlByContent(String content)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(URL_START).Append(content).Append(URL_END);
            return sb.ToString();
        }
    }
}
